<template>
  <div class="edit-content-warpper">
    <el-form
      ref="ruleform"
      :inline="true"
      :model="form"
      :rules="rules"
      label-width="100px"
    >
      <el-row>
        <el-form-item label="增加前后缀：" prop="addFix">
          <el-input
            v-model="form.addPrefix"
            placeholder="输入前缀"
            style="width: 240px;"
          />
          +原标题+
          <el-input
            v-model="form.addSuffix"
            placeholder="输入后缀"
            style="width: 240px;"
          />
        </el-form-item>
      </el-row>
      <el-row class="replace-keywords-row">
        <el-form-item
          v-for="(item, index) in form.replaceKeywords"
          :key="index"
          label="替换关键字："
          :prop="'domains' + index + 'value'"
        >
          <el-input
            v-model="item.replaceBefore"
            placeholder="输入内容"
            style="width: 240px;"
          />
          <span style="margin: 0 8px;">替换为-></span>
          <el-input
            v-model="item.replaceAfter"
            placeholder="输入内容"
            style="width: 240px;"
          />
          <span style="font-size: 24px; vertical-align: middle; margin-left: 12px;">
            <i v-if="index === 0" class="el-icon-circle-plus-outline" style="color: #4E78EF; cursor: pointer;" @click="addDomain" />
            <i v-else class="el-icon-remove-outline" style="color: #EE0000; cursor: pointer;" @click.prevent="removeDomain(item)" />
          </span>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="删除关键字：" prop="delkeywords" class="keywords-textarea">
          <el-input
            v-model="form.delkeywords"
            type="textarea"
            placeholder="多个关键字用回车或者英文逗号分隔"
          />
        </el-form-item>
        <el-button @click="form.delkeywords = ''">清空</el-button>
      </el-row>
      <el-row>
        <el-form-item label="删除标题前：" prop="delTitleBefore">
          <el-input
            v-model.number="form.delTitleBefore"
            placeholder="请输入数字"
            style="width: 240px;"
          /> 个字
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="删除标题后：" prop="delTitleAfter">
          <el-input
            v-model.number="form.delTitleAfter"
            placeholder="请输入数字"
            style="width: 240px;"
          /> 个字
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="超出字数：">
          <el-radio-group v-model="form.overWrite" v-removeAriaHidden>
            <el-radio v-for="item in pageInfo.overWriteArr" :key="item.value" :label="item.value">{{ item.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-row>
    </el-form>
    <p style="color: #EE0000;">注意：如使用多种处理方式，则处理顺序为：删除 > 替换 > 添加前后缀</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      pageInfo: {
        overWriteArr: [
          {
            label: '截掉尾部内容',
            value: 0
          },
          {
            label: '截掉头部内容',
            value: 1
          }
        ]
      },
      form: {
        addPrefix: '',
        addSuffix: '',
        replaceKeywords: [
          {
            replaceBefore: '',
            replaceAfter: ''
          },
          {
            replaceBefore: '',
            replaceAfter: ''
          }
        ],
        delkeywords: '',
        delTitleBefore: '',
        delTitleAfter: '',
        overWrite: 0
      },
      rules: {}
    }
  },
  methods: {
    addDomain() {
      this.form.replaceKeywords.push({
        replaceBefore: '',
        replaceAfter: ''
      })
    },
    removeDomain(item) {
      var index = this.form.replaceKeywords.indexOf(item)
      if (index !== -1) {
        this.form.replaceKeywords.splice(index, 1)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
p {
  margin: 0;
  line-height: 17px;
}
.edit-content-warpper {
  .replace-keywords-row {
    ::v-deep {
      .el-form-item {
        &:first-of-type .el-form-item__label {
          opacity: 1;
        }
        .el-form-item__label {
          opacity: 0;
        }
      }
    }
  }
  .keywords-textarea {
    ::v-deep {
      .el-textarea {
        width: 760px;
      }
      .el-textarea__inner {
        height: 80px;
        background-color: #F7F8FA;
        border: none;
      }
    }
  }
}
</style>
